﻿@using System.Globalization
@model  List<string>
@{
    ViewBag.Title = "数据源表列表";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script src="@Url.Content("~/Scripts/dictionary.js")" type="text/javascript"></script>
    <style>
        .spnWildCard
        {
            display: none;
        }
    </style>
    <script type="text/javascript">
        var clickAll = true;
        var UrlArray = $.getUrlArray();
        var selectedArray = new Array();
        var ExtNames = new Array();
        var dbty = '@Model[0]';
        var opts = {
            rows: 10,
            height: 450,
            url: "/SystemConfiguration/GetSourceTBList?id=" + UrlArray["systemID"] + "&dbName=" + encodeURI(UrlArray["dbName"]),
            para: {},
            idField: "Guid",
            checkbox: true,
            rownumbers: true,
            columns: [
                    { field: 'ViewName', title: '表名称', width: 40, sortable: true },
                    { field: 'ViewChnName', title: '表说明', width: 40, sortable: true },
                    { field: 'Guid', title: '操作', width: 20, align: 'center'
                        , formatter: function (value, rowData, rowIndex) {
                            var chnName = "";
                            if (dbty == "3" || dbty == "5" || dbty == "6" || dbty == "7")
                                chnName = rowData.ViewChnName.replace(/\\/g, "\\\\");
                            var a = "<select onchange='openTBData(\"" + rowData.ViewName.replace(/\"/g, "~") + "\",\"" + rowData.DBID + "\",\"" + chnName + "\")' style='width: 120px; '><option value=''>-请选择-</option>";
                            var ac2 = a + "<option>预览数据源信息</option></select>";
                            return ac2;
                        }
                    }
                    ],
            OnChickRow: function (value, rowData, rowIndex) {
                return clickRow(value, rowData, rowIndex, true);

            }
        };
        function initDataGridView(p) {
            opts.para["tableName"] = $.trim($("#txtName").val())
            opts.para["wildCard"] = $.trim($("#txtWildCard").val())
            if (p == 1)
                thisPageNum = 1;
            $("#DataGrid2").dg(opts);
        }
        $(function () {
            if (!(dbty == "1" || dbty == "2" || dbty == "4" || dbty == "8")) {
                $(".spnWildCard").show();
                var dblist = '@Model[1]'.split("$");
                for (var i = 0; i < dblist.length; i++) {
                    $("#txtWildCard").append("<option>" + dblist[i] + "</option>");
                }
            }
            initDataGridView();
        });
        function openTBData(viewName, sourceDBID, fileName) {
            var id = UrlArray["systemID"];
            var dbName = encodeURI(UrlArray["dbName"]);
            if (fileName && fileName.indexOf(";") > 0)
                fileName = fileName.split(";")[1];
            var url = "/SystemConfiguration/SourceTBData/?systemID=" + id + "&fileName=" + fileName + "&viewName=" + viewName + "&DBID=" + sourceDBID + "&dbName=" + dbName + "&DBType=" + UrlArray["DBType"];
            showModalMany('Contact', url, '810', '430', "off");
            initDataGridView();
        }
        function onbtnCloseCilck() {
            if (selectedArray.length == 0) {
                alert('请选择一条数据!');
                return false;
            }
            returnParent(selectedArray);
            return false;
        }
        function updateSelectedUI(load) {
            // 待续
            var span = "";
            for (var i = 0; i < selectedArray.length; i++) {
                var info = selectedArray[i];
                span += "<span class=\"s1\">" + info.ViewName
            + "<a href=\"javascript:void(0)\" onclick=\"delSelected('" + info.Guid + "')\">"
            + "<span class=\"s2\">&nbsp;X&nbsp;</span></a></span>";
            }

            $('#selectDiv').html(span);
            if (load) {
                opts.para["ExtNames"] = ExtNames.join(",");
                initDataGridView();
            }
        }
        function clickRow(guid, rowInfo, rowIndex, load) {
            if (selectedArray.SubIndexOf(guid) == -1) {
                var obj = {};
                obj["Guid"] = rowInfo.Guid;
                obj["ViewName"] = rowInfo.ViewName;
                obj["ViewChnName"] = rowInfo.ViewChnName;
                obj["DBID"] = rowInfo.DBID;
                obj["WildCardID"] = rowInfo.WildCardID;
                selectedArray.push(obj);
                ExtNames.push(rowInfo.ViewName);
            }
            updateSelectedUI(load);
            return true;
        }
        function delSelected(guid) {
            var i = selectedArray.SubIndexOf(guid);
            if (i > -1) {
                selectedArray.removeAt(i);
                ExtNames.removeAt(i);
            }
            updateSelectedUI(true);
        }

    </script>
}
<div style="margin: 5px; height: 470px; overflow-y: scroll;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                预览源系统表信息
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                表名称：<input id="txtName" type="text" class="inputSearch" style="width: 200px;" />
                <span class="spnWildCard">通配符：<select id="txtWildCard"><option value="">-请选择-</option>
                </select></span>
                <input id="buttonSearch" class="button" type="button" value=" 搜索 " onclick="initDataGridView(1)" />
            </td>
        </tr>
    </table>
    <table width="100%;" id="selected">
        <tr>
            <td width="50" valign="top">
                已选择：
            </td>
            <td>
                <div id="selectDiv" style="display: block;">
                </div>
            </td>
            <td width="50" valign="top">
                <input class="button" type="button" value=" 确定 " onclick="onbtnCloseCilck()" />
            </td>
        </tr>
    </table>
    <div style="margin: 0px;">
        <table class="listTitle">
            <tr>
                <td width="15">
                    <img src="/images/filesave.png" />
                </td>
                <td width="300">
                    源系统表列表
                </td>
                <td align="right">
                </td>
            </tr>
        </table>
        <table id="DataGrid2" class="pagTable" cellpadding="0" cellspacing="0">
        </table>
        <div>
            <div id="Pagination" class="pagination">
            </div>
            <div id="loading" class="loading">
                <img src="/Images/tree_loading.gif" />
            </div>
        </div>
        <div id="msg">
        </div>
    </div>
</div>
